import os
from time import sleep

import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service
from selenium.webdriver.support.wait import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

ep = 'E:\Edge\Driver\edgedriver_win32\msedgedriver.exe'

@pytest.fixture(scope="function")
def generatedriver():
    service = Service(executable_path=ep)
    driver=webdriver.Edge(service=service)
    driver.maximize_window()
    driver.implicitly_wait(6)
    driver.get(os.getenv('BASEURL'))
    yield driver
    driver.quit()


@pytest.fixture(scope="function")
def login_success():
    service = Service(executable_path=ep)
    driver = webdriver.Edge(service=service)
    driver.maximize_window()
    driver.implicitly_wait(6)
    driver.get(os.getenv('BASEURL'))

    b = WebDriverWait(driver, 10, 1).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, '#app > div > form > button'))
    )
    b.click()
    sleep(5)

    yield driver
    driver.quit()


